<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-05 12:05:33
 * @LastEditTime: 2023-10-20 10:45:41
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Http\Services\Report;

use App\Http\Services\Service;
use App\Models\ProPot;
use App\Repositories\LoomRepository;

class LoomService extends Service
    {

    public $loom;
    public function boot(LoomRepository $loom)
        {
        $this->loom = $loom;
        }
    public function potList()
        {

        }
    public function list()
        {
        $list = $this->loom->whereStatusId(0)->condition(request())->orderBy("dosage")->getList();

        $list = $list->map(function ($v)
            {
            $v            = $v->toArray();
            $list         = ProPot::wherePotdate(date("Y-m-d"))->whereLoom_id($v['id'])->whereIsKk(1)->get();
            $v['kkcount'] = $v['kkquntity'] = 0;
            $list->filter(function ($pot) use (&$v)
                {
                $v['kkcount'] += 1;
                $v['kkquntity'] += $pot->quantity;
                });
            //当前排队 
            $list           = ProPot::whereProcessId(10)->whereIsKk(1)->whereLoom_id($v['id'])->get();
            $v['waitcount'] = $v['waitquntity'] = 0;
            $list->filter(function ($pot) use (&$v)
                {
                $v['waitcount'] += 1;
                $v['waitquntity'] += $pot->quantity;
                });

            $list         = ProPot::where("potdate", '<', date("Y-m-d"))->whereLoom_id($v['id'])->whereIsKk(0)->get();
            $v['bfcount'] = $v['bfquntity'] = 0;
            $list->filter(function ($pot) use (&$v)
                {
                $v['bfcount'] += 1;
                $v['bfquntity'] += $pot->quantity;
                });

            $list         = ProPot::wherePotdate(date("Y-m-d"))->whereIsKk(0)->whereLoom_id($v['id'])->get();
            $v['btcount'] = $v['btquntity'] = 0;
            $list->filter(function ($pot) use (&$v)
                {
                $v['btcount'] += 1;
                $v['btquntity'] += $pot->quantity;
                });
            $list         = ProPot::where('potdate', '>', date("Y-m-d"))->whereIsKk(0)->whereLoom_id($v['id'])->get();
            $v['afcount'] = $v['afquntity'] = 0;
            $list->filter(function ($pot) use (&$v)
                {
                $v['afcount'] += 1;
                $v['afquntity'] += $pot->quantity;
                });
            return $v;
            });
        return $list;
        }

    }